import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
//import Mock from './mock'
//Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'

//配置axios
import axios from 'axios'

//配置axios的全局基本路径 ,后台路径
axios.defaults.baseURL='http://localhost:1030/services'

import BaiduMap from 'vue-baidu-map'
Vue.use(BaiduMap, {
    ak: 'PGzy3WGjN6tg5HGQB1G1i8BQGWdO2vOY'
})

//全局属性配置，在任意组件内可以使用this.$http获取axios对象
Vue.prototype.$http = axios

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//拦截器
axios.interceptors.request.use(config => {
  //1.从sessionStorage中获取 sessionId
  //2.给请求头添加属性sessionId

  var sessionId = sessionStorage.getItem('sessionId');
  if (sessionId) {
    // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
    config.headers['X-Token'] = sessionId;
  }
  return config
}, error => {
  // Do something with request error
  Promise.reject(error)
});



//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  routes
})

//所有的url执行之前 ，都会被这里拦截到

/*
router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    // sessionStorage:可以看做是浏览器的session，前段用来存储东西的
    sessionStorage.removeItem('user');
  }
  //获取session中的user
  let user = JSON.parse(sessionStorage.getItem('user'));

  //处理如果不是登录路径，如果你没登录，就跳到登录路径
  if (!user &&  (to.path != '/login'  && to.path != '/WxLoginSuccess')){
    //如果不是访问登录，你又没登录，调到登录页面
    next({ path: '/login' })
  } else {
    //登录了，直接跳转到要跳转的页面
    next()
  }
});
*/

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

